<?php

namespace App\Http\Controllers\Backend\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Backend\BaseController;
use App\Repository\Repositories\Interfaces\CompanyRepository;
use App\Repository\Repositories\Interfaces\UserRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\ConstDir\ErrorConst;
use Illuminate\Support\Facades\DB;


/**
 * 公司管理
 *
 * @package App\Http\Controllers\Backend
 */
class CompanyController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    protected $company_repo;

    public function __construct(CompanyRepository $company_repo)
    {
        $this->company_repo = $company_repo;
    }


    public function index()
    {


    }


    public function show($id)
    {

    }

    public function update(UserRepository $user_repo,Request $request , $id)
    {

        $this->validate($request, [
            'update_type' => 'required',
            'step' => 'sometimes|required|numeric',
            'fail_reason' => 'sometimes|required',
        ]);
        $data = $request->all();

        if($data['update_type'] == 'update_step'){
            $value['step'] = $data['step'];
            $user_parm = [
                'identification_type'=>1
            ];

        }elseif ($data['update_type'] == 'update_fail_reason') {

            $value['step'] = $data['step'];
            $value['fail_reason'] = $data['fail_reason'];

            $user_parm = [
                'identification_type'=>3
            ];

        }

        $ret = $this->company_repo->update($value, $id);
        if ($ret) {
            $user_ret = $user_repo->update($user_parm,$ret['data']['user_id']);
            return $this->success(ErrorConst::SUCCESS_CODE_MSG, ErrorConst::SUCCESS_CODE);
        } else {
            return $this->error(ErrorConst::FAILED_CODE_MSG);
        }
    }




}
